package deleteface.bank.jqsoft.cn.deleteface;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.flyco.tablayout.SegmentTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.tencent.bugly.Bugly;

import java.util.ArrayList;

import cn.jqsoft.bank.deleteface.R;
import deleteface.bank.jqsoft.cn.deleteface.ui.FloatBackground;
import deleteface.bank.jqsoft.cn.deleteface.ui.FloatCircle;
import deleteface.bank.jqsoft.cn.deleteface.ui.FloatRect;
import deleteface.bank.jqsoft.cn.deleteface.ui.FloatRing;
import deleteface.bank.jqsoft.cn.deleteface.ui.FloatText;

public class MainViewPageActivity  extends AppCompatActivity {
    SegmentTabLayout mTabLayout;
    ViewPager vpContent;
    private ArrayList<Fragment> mFragments = new ArrayList<>();

    private String[] mTitles = {"单个删除", "批量删除"};

    private int[] mIconUnselectIds = {
            R.mipmap.ic_launcher_round, R.mipmap.ic_launcher_round};
    private int[] mIconSelectIds = {
            R.mipmap.ic_launcher_round, R.mipmap.ic_launcher_round};

    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    DeleteFaceForSingle deleteFaceForSingle;
    DeleteFaceForMany deleteFaceForMany;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_view);
        Bugly.init(getApplicationContext(), "d245786e9c", false);

        mTabLayout=(SegmentTabLayout)findViewById(R.id.ctl_head);
        vpContent=(ViewPager)findViewById(R.id.vp_content);
        HasMine();

    }

    private void HasMine(){

        for (int i = 0; i < mTitles.length; ++i){
            if (i==0){

                deleteFaceForSingle = new DeleteFaceForSingle();
                mFragments.add(deleteFaceForSingle);


            } else if (i==1) {
                deleteFaceForMany = new DeleteFaceForMany();
                mFragments.add(deleteFaceForMany);

            }
            else {
                String title = mTitles[i];
            }
        }



        for (int i = 0; i < mTitles.length; i++) {
            mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]));
        }
        mTabLayout.setTextUnselectColor(getResources().getColor(R.color.white));
        vpContent.setOffscreenPageLimit(5);
        vpContent.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
        initTabData();
    }

    private void initTabData() {
        vpContent=(ViewPager)findViewById(R.id.vp_content);
        mTabLayout.setTabData(mTitles);

        mTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                vpContent.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {
//                if (position == 0) {
//                    mTabLayout.showMsg(0, mRandom.nextInt(100) + 1);
////                    UnreadMsgUtils.show(mTabLayout.getMsgView(0), mRandom.nextInt(100) + 1);
//                }
            }
        });

        vpContent.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mTabLayout.setCurrentTab(position);
//                reassignToolbar(mFragments.get(position));
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }



    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(android.support.v4.app.FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }

}
